
# Swarm makefile

include config.mak

PROGRAM_OBJECTS=swarm.o
OBJECTS=$(NATIVE) swarms.o display.o swarmio.o hash.o swarmio_command.o \
	native.o sym_table.o sw_signal.o force.o insect.o random.o simulate.o

INCLUDE=-I.
LIBS=$(GTK_LIBS) -lc -lm -lpthread -lgthread-2.0
TESTS=sw_test hash_test swarmio_test display_test

### Main program section

all: libswarm.so swarm swarm-test swarm-bin

swarm-bin:
	if [ ! -e ../bin ]; then \
		mkdir ../bin ; \
	fi
	cp -f *.so* ../bin
	cp -f swarm ../bin
	cp -f $(TESTS) ../bin

swarm: libswarm.so $(PROGRAM_OBJECTS) # This is the program swarm.
	gcc $(PROGRAM_OBJECTS) -o swarm $(LIBS) -L. -lswarm

### Testing stuff here

swarm-test: libswarm.so $(TESTS) # Compile the test programs.


test: swarm-test # Compile the tests and then run them.


### Library and object compilation

libswarm.so: $(OBJECTS) # Build the swarm library.
	ld -shared -soname libswarm.so -o libswarm.so.$(VERSION) \
                $(OBJECTS) $(LIBS)
	ldconfig -v -n .

.c.o:
	$(CC) $(C_FLAGS) $(INCLUDE) $<
.s.o:
	$(ASM) $(ASM_FLAGS) $<
.c:
	$(CC) $(C_TEST_FLAGS) $(INCLUDE) $(LIBS) -L. -lswarm $< -o $@

### Cleanup targets

clean:
	rm -f *.o
	rm -f swarm
	rm -f libswarm.*
	rm -f $(TESTS)

dist-clean: clean
	rm -f config.h config.mak
